<script type="text/javascript" src="java/formval.js"></script>
<script type="text/javascript">
function validateOnSubmit(formElem) {
	var elem;
	var errs=0;
	if (!validatePresent(formElem.Kuchentyp,  'KuchentypError', true))  			errs = 1;
	if (!validatePresent(formElem.ResturantName,  'ResturantNameError', true))  			errs = 1;
	
	if (errs==0){
		formElem.submit();
	}
};
</script>
<?php

if(!empty($_SESSION["CMS_User"]["ID"])){
	$FirmaID = $_GET["FirmaID"];
	$AbteilungID = $_GET["AbteilungID"];
	$ResturantID = $_GET['ResturantID'];
	if($_POST){
		if(!empty($_POST["ResturantID"])){//edit
			if(!empty($_POST["ResturantName"])&&!empty($_POST["Kuchentyp"])){
				$ResturantID=$_POST["ResturantID"];
				$sql="update resturant set 
				AbteilungID= $AbteilungID
				,ResturantName='".$_POST["ResturantName"]."'
				,MittagEssen='".$_POST['MittagEssen']."'
				,Abendessen='".$_POST["Abendessen"]."'
				,Ruhetage='".$_POST["Ruhetage"]."'
				,GeoffnetFeiertage='".$_POST["GeoffnetFeiertage"]."'
				,Kuchentyp='".$_POST["Kuchentyp"]."'" .
				",MenuPreis='".$_POST["MenuPreis"]."'" .
				",KinderMenu='".$_POST["KinderMenu"]."'" .
				",Service='".$_POST["Service"]."'
				where ID=$ResturantID";
				//echo $sql;
				$_rd=mysql_query($sql,$_db_link);
			}
			}else {//Add
			if(!empty($_POST["ResturantName"])&&!empty($_POST["Kuchentyp"])){
			     $sql="insert into 
			     resturant (AbteilungID,ResturantName,MittagEssen,Abendessen,Ruhetage,GeoffnetFeiertage,Kuchentyp,MenuPreis,KinderMenu,Service) 
				values($AbteilungID
				,'".$_POST["ResturantName"]."'
				,'".$_POST["MittagEssen"]."'
				,'".$_POST["Abendessen"]."'
				,'".$_POST["Ruhetage"]."'
				,'".$_POST["GeoffnetFeiertage"]."'
				,'".$_POST["Kuchentyp"]."'
				,'".$_POST["MenuPreis"]."'" .
				",'".$_POST["KinderMenu"]."'" .
				",'".$_POST["Service"]."')";
				//echo $sql;
				$_rd= mysql_query($sql,$_db_link); 
				$ResturantID = mysql_insert_id();
			}
		}
	}
	}		
if($AbteilungID!= NULL && $AbteilungID!=0){

	if($ResturantID!=NULL && $ResturantID!=0){
		$sql="select * FROM resturant WHERE ID=$ResturantID";
		$_rd= mysql_query($sql,$_db_link);
		if($_rd){
			$daten=mysql_fetch_array($_rd,MYSQL_ASSOC);
		}
	}
	?>
	<div style="width:100%;background-color:#F1EEF3;margin:0px"> 
	<table class="tableEdit">
	<?PHP if(isset($ResturantID)){ ?>
		<tr>
		<td class="lableEdit"><?PHP  LangText("ID");?>:</td>
		<td class="inputEdit"><input type="text" name="ResturantID" id="ResturantID" READONLY value='<?PHP echo $ResturantID; ?>' /></td>
		<td class="validateEdit"></td>
		</tr>
		<?PHP } ?>
	<tr>
	<td class="lableEdit"><?PHP  LangText("AbteilungID");?>:</td>
	<td class="inputEdit"><input type="text" name="AbteilungID" id="AbteilungID" READONLY value='<?PHP echo $AbteilungID; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("ResturantName");?>:*</td>
	<td class="inputEdit"><input name="ResturantName"  onchange="validatePresent(this, 'ResturantNameError');" id="ResturantName" value='<?PHP echo $daten["ResturantName"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="ResturantNameError" value='<?PHP LangText("ResturantNameError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Kuchentyp");?>:*</td>
	<td class="inputEdit"><input name="Kuchentyp"  onchange="validatePresent(this, 'KuchentypError');" id="Kuchentyp" value='<?PHP echo $daten["Kuchentyp"]; ?>' /></td>
	<td class="validateEdit"><input type="label"  DISABLED  id="KuchentypError" value='<?PHP LangText("KuchentypError");?>' /></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("MittagEssen");?>:</td>
	<td class="inputEdit"><textarea name="MittagEssen"  id="MittagEssen"><?PHP echo $daten["MittagEssen"]; ?></textarea></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Abendessen");?>:</td>
	<td class="inputEdit"><textarea name="Abendessen"  id="Abendessen"><?PHP echo $daten["Abendessen"]; ?></textarea></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Ruhetage");?>:</td>
	<td class="inputEdit"><textarea name="Ruhetage"  id="Ruhetage"><?PHP echo $daten["Ruhetage"]; ?></textarea></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("GeoffnetFeiertage");?>:</td>
	<td class="inputEdit"><textarea name="GeoffnetFeiertage"  id="GeoffnetFeiertage"><?PHP echo $daten["GeoffnetFeiertage"]; ?></textarea></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("Service");?>:</td>
	<td class="inputEdit"><textarea name="Service"  id="Service"><?PHP echo $daten["Service"]; ?></textarea></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("MenuPreis");?>:</td>
	<td class="inputEdit"><input name="MenuPreis" id="MenuPreis" value='<?PHP echo $daten["MenuPreis"]; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	<tr>
	<td class="lableEdit"><?PHP  LangText("KinderMenu");?>:</td>
	<td class="inputEdit"><input name="KinderMenu" id="KinderMenu" value='<?PHP echo $daten["KinderMenu"]; ?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	
	<tr>
	<td class="lableEdit"></td>
	<td class="inputEdit"><input type="button"  onclick="validateOnSubmit(this.form);" class="BootenLink" value='<?PHP if($ResturantID!=NULL && $ResturantID != 0 ){LangText("Bearbeiten");}else{ LangText("Himzufugen");}?>' />
	<input type="button"  onclick="window.location='index.php?tag=<?PHP echo $_GET['tag']; ?>&page=AbteilungEditPro&FirmaID=<?PHP echo $FirmaID; ?>&AbteilungID=<?PHP echo $AbteilungID; ?>&MoudeTagID=<?PHP echo $_GET['MoudeTagID']; ?>'" class="BootenLink" value='<?PHP LangText("Abbrechen");?>' /></td>
	<td class="validateEdit"></td>
	</tr>
	</table>
	</div>
	
	<?php
}
?> 